package com.egoo.ticket.server.controller;

import com.egoo.ticket.server.pojo.vo.InteractiveDataVo;
import com.egoo.ticket.server.service.DepartmentService;
import com.egoo.ticket.server.utils.common.ConstantCode;
import com.egoo.ticket.server.utils.common.DbResponse;
import com.egoo.ticket.server.utils.common.ResponseConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Donny_Dong
 */
@RestController
@RequestMapping(value = "/v1/department", produces = "application/json")
@Api(value = "部门管理",tags = "部门管理",description = "部门管理")
@Slf4j
public class DepartmentController {

	@Autowired
	private DepartmentService departmentService;

	@ApiOperation(value = "查询机构树列表", notes = "查询机构树列表")
	@RequestMapping(method = RequestMethod.GET, value="/getDepartmentTreeData")
	public DbResponse getDepartmentTreeData(HttpServletRequest request){
		String userId = request.getHeader(ConstantCode.CurrentUserInfo.USER_ID);
		String tenantId = request.getHeader(ConstantCode.CurrentUserInfo.TENANT_ID);
		try {

			List<InteractiveDataVo> departmentTreeData = departmentService.getDepartmentTreeData(tenantId);

			return new DbResponse(ResponseConstant.RES_SUCCESS_CODE,
					ResponseConstant.SELECT_SUCCESS_MSG,departmentTreeData);

		} catch (Exception e) {
			log.error("查询机构树列表异常："+e);
			return new DbResponse(ResponseConstant.RES_FAIL_CODE,"查询机构树列表异常："+e);
		}
	}

}
